<template>
  <div>
    <!-- <attr-select :dataSource="dataSource" :filter="filter" v-model="key" /> -->
    <!-- <p>所选病例数：{{all_count}}；发病病例数{{valiad_count}}</p> -->
    <!-- <p> 高亮显示RR值大于<el-input-number size="mini" v-model="high_light" :min="0" :max="1" :precision="2" :step="0.1"/> </p> -->
     <div class="ana-detail-title" style="position: relative">
      <a-icon type="forward" />分层分析
    </div>
    <el-table :data="tableData" border :row-class-name="tableRowClassName">
      <el-table-column prop="x1" label="牛奶" width="140"> </el-table-column>
      <el-table-column prop="x2" label="蛋糕" width="140"> </el-table-column>
      <el-table-column prop="count1" label="病例组" width="140">
      </el-table-column>
      <el-table-column prop="count2" label="对照组" width="140">
      </el-table-column>
        <el-table-column prop="or" label="OR" width="140">
      </el-table-column>
      <el-table-column prop="ci" label="95%CI" width="140">
      </el-table-column>
      <!-- </el-table-column>
      <el-table-column label="病例组">
        
      </el-table-column>
      <el-table-column label="未暴露组">
        <el-table-column prop="count2" label="发病" width="140">
        </el-table-column>
        <el-table-column prop="ratio2" label="未发病" width="140">
        </el-table-column>
      </el-table-column>
      <el-table-column label="RR值">
        <el-table-column prop="RR" label="RR值" width="140"> </el-table-column>
        <el-table-column prop="RR_P" label="P值" width="140"> </el-table-column>
      </el-table-column> -->
    </el-table>
    <!-- <div class="info">
      OR=80×60/20×40=6.0，95%CI=3.1-12
    </div> -->
  </div>
</template>

<script>
import { isArray, isString } from "@/utils/utils";
import AttrSelect from "../utils/AttrSelect.vue";
import Moment from "@/utils/moment.zh_cn";
export default {
  components: {
    AttrSelect,
  },
  data() {
    return {
      key: "食物",
      tableData: [],
      all_count: 0,
      valiad_count: 0,
      high_light: 0.8,
    };
  },
  props: {
    dataSource: Array,
  },
  watch: {
    key: function (v, o) {
      this.reproject();
    },
    dataSource: function (v, o) {
      this.reproject();
    },
    high_light: function (v, o) {
      // this.reproject();
    },
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (row["RR"] >= this.high_light) {
        return "warning-row";
      }
      return "";
    },

    reproject() {
      // let stateKey = "发病人员";
      // let data = this.dataSource.reduce((pre, value) => {
      //   if (value[stateKey]) {
      //     let sets = pre["k1"] || {};
      //     if (value[this.key]) {
      //       let v = value[this.key];
      //       if (isArray(v) && v.length && v.length > 0) {
      //         v.forEach((vv) => {
      //           if (isString(vv)) {
      //             if (vv in sets) {
      //               sets[vv] += 1;
      //             } else {
      //               sets[vv] = 1;
      //             }
      //           }
      //         });
      //       } else {
      //         if (v in sets) {
      //           sets[v] += 1;
      //         } else {
      //           sets[v] = 1;
      //         }
      //       }
      //     }
      //   } else {
      //     let sets = pre["k2"] || {};
      //     if (value[this.key]) {
      //       let v = value[this.key];
      //       if (isArray(v) && v.length && v.length > 0) {
      //         v.forEach((vv) => {
      //           if (isString(vv)) {
      //             if (vv in sets) {
      //               sets[vv] += 1;
      //             } else {
      //               sets[vv] = 1;
      //             }
      //           }
      //         });
      //       } else {
      //         if (v in sets) {
      //           sets[v] += 1;
      //         } else {
      //           sets[v] = 1;
      //         }
      //       }
      //     }
      //   }
      //   return pre;
      // }, {});

      let reproject = [
        {
          x1: "食用",
          x2: '食用',
          count1: 72,
          count2: 36,
          or: 6.0,
          ci: '2.9-12'
        },
        {
          x1: "食用",
          x2: '未食用',
          count1: 2,
          count2: 6,
          or: 1.0,
          ci: '0.09-6.3'
        }, {
          x1: "未食用",
          x2: '食用',
          count1: 8,
          count2: 4,
          or: 6.0,
          ci: '1.4-27'
        }, {
          x1: "未食用",
          x2: '未食用',
          count1: 18,
          count2: 54,
          or: '-',
          ci: '-'
        },
      ];
      // let keys = [...Object.keys(data.k1), ...Object.keys(data.k2)];
      // let sets = {};
      // keys.forEach((k) => {
      //   if(k in sets){
      //     return
      //   }
      //   else{
      //     sets[k] = 1
      //   }
      //   reproject.push({
      //     x: k === "undefined" ? "未填写" : k,
      //     count1: data.k1[k] || 0,
      //     ratio1: data.k2[k] || 0,
      //     count2: valiad_count - sets[k],
      //     ratio2: ((valiad_count - sets[k]) / valiad_count) * 100,
      //     RR: (sets[k] === valiad_count
      //       ? Infinity
      //       : sets[k] / (valiad_count - sets[k])
      //     ).toFixed(2),
      //     RR_P: 0,
      //   });
      // });
      this.tableData = reproject;
      return reproject;
    },
    init() {
      this.reproject();
    },
  },

  mounted() {
    this.init();
  },
};
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}
</style>